package com.yc.springmvc;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.support.StandardServletMultipartResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
@ComponentScan("com.yc.springmvc")
@EnableWebMvc
public class MVCConfig implements WebMvcConfigurer {


//    @Override
//    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
//        configurer.enable();
//    }


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        //addResourceHandler("/**") 表示将所有的请求路径映射到静态资源处理器。
//addResourceLocations("D:/IDEA2022.3/daimacangku/daima/spring-MVC/src/main/webapp/")
// 表示指定静态资源所在的目录或路径。在这个例子中，
// 静态资源的根目录被设置为D:/IDEA2022.3/daimacangku/daima/spring-MVC/src/main/webapp/。
        registry.addResourceHandler("/**")
                .addResourceLocations("file:/D:/IDEA2022.3/daimacangku/daima/spring-mvc1/src/main/webapp/");

        registry.addResourceHandler("/upload/**")
                .addResourceLocations("file:D:/学习资料/s3/spring-mvc04/上传文件/");
    }




    @Bean
    public MultipartResolver multipartResolver(){    //MultipartResolver用于处理文件上传的请求
        return new StandardServletMultipartResolver();
    }



}
